<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
  <title>HELLO, AMAP!</title>
  <style>
    html,
    body,
    #container {
      width: 100%;
      height: 100%;
    }
  </style>
</head>

<body>
  <div id="container"></div>
</body>
<script type="text/javascript">
  window._AMapSecurityConfig = {
    securityJsCode: "d522601a6afc7f91796728190ea8748a",
  };
</script>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=6b3a0bf04070a13557dbc45fae249ada"></script>
<script type="text/javascript">
  var map= new AMap.Map("container", {
            zoom: 16, //级别
            center: [121.47592, 31.237687], //中心点坐标
        })
  // AMapLoader.load({
  //   key: "6b3a0bf04070a13557dbc45fae249ada", //申请好的Web端开发者key，调用 load 时必填
  //   version: "2.0", //指定要加载的 JS API 的版本，缺省时默认为 1.4.15
  // })
  //   .then((AMap) => {
  //     //JS API 加载完成后获取AMap对象
  //     map = new AMap.Map("container", {
  //       viewMode: '2D', //默认使用 2D 模式
  //       zoom: 11, //地图级别
  //       center: [116.397428, 39.90923], //地图中心点
  //     });
  //   })
  //   .catch((e) => {
  //     console.error(e); //加载错误提示
  //   });

  function getLocation(lon, lat) {
    //1.重新定位当前位置
    map.setZoomAndCenter(18, [lon, lat])
    //2.提供4个最近位置
    map.plugin(['AMap.PlaceSearch'], function () {
      var PlaceSearchOptions = { //设置PlaceSearch属性
        pageSize: 4, //每页结果数,默认10
        pageIndex: 1, //请求页码，默认1
        extensions: "base" //返回信息详略，默认为base（基本信息）
      };
      var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
      window.swift.alert("进入addListener()之前")
      AMap.event.addListener(MSearch, "complete",  (res)=>{
        window.swift.receiveData(JSON.stringify(res?.poiList?.pois ||  []))
      }); //返回结果
      MSearch.searchNearBy('麓雅居', new AMap.LngLat(lon, lat)); //关键字查询
    });
  }

  window.onload = function () {
    if (window.swift) {
      window.swift.getLocation()
    }
  }

</script>

</html>